// //启动并且连接redis
const Redis = require("redis");
const initArticles  =require('./articlesinit.js')
const initViewCount = require('../ORM/custom/controller/website/initViewCount.js')
const redisClient = Redis.createClient({
  url: "redis://www.beloved.ltd:6379" 
});
// 配置redis的监听事件
// 准备连接redis-server事件
(async () => {
  redisClient.on("ready", function () {
    console.log("Redis client: ready at " );
  });
  // 连接到redis-server回调事件
  redisClient.on("connect", function () {
    console.log("redis is now connected!");
  });
  redisClient.on("reconnecting", function () {
    console.log("redis reconnecting");
  });
  redisClient.on("end", function () {
    console.log("Redis Closed!");
  });
  redisClient.on("warning", function () {
    console.log("Redis client: warning");
  });
  redisClient.on("error", function (err) {
  
    console.error("Redis Error " + err);
  });
  //连接redis
  await redisClient.connect();
  // 初始化文章数据
  initArticles(redisClient)
  initViewCount(redisClient)
  //初始化网站浏览量数据
})();

// 导出redis-client对象
module.exports = redisClient;
